﻿/*
 * GNU GENERAL PUBLIC LICENSE v2
 * 
 * Developers: Alan Audette, Oguz Bastemur
 */
namespace SqlDatabaseBackup.Helper
{
    using System.Diagnostics;

    internal static class Log
    {
        /// <summary>
        /// Records a message in the event log
        /// </summary>
        /// <param name="message"></param>
        /// <param name="type"> </param>
        internal static void Message(string message, EventLogEntryType type = EventLogEntryType.Information)
        {
            // Create the event log source if it does not exist
            if (!EventLog.SourceExists(Program.configuration.Logging.SourceName))
                EventLog.CreateEventSource(Program.configuration.Logging.SourceName, Program.configuration.Logging.LogName);

            // Create the eventlog object
            EventLog log = new EventLog();
            log.Source = Program.configuration.Logging.SourceName;

            // Add the message to the event log
            log.WriteEntry(message, type);

            if (type == EventLogEntryType.Error || type == EventLogEntryType.Warning)
                ToConsole.RedText(message);
            else if (type == EventLogEntryType.Information || type == EventLogEntryType.FailureAudit)
                ToConsole.WriteLine(message);
            else
                ToConsole.GreenText(message);
        }
    }
}